package com.mostromas.ess.product.controller;


import com.mostromas.ess.entities.ExecutiveStandards;
import com.mostromas.ess.entities.ProductSize;
import com.mostromas.ess.product.service.IExecutiveStandardsService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 执行标准表-前端控制器
 */
@Api(value = "执行标准管理接口",description = "执行标准管理接口，提供执行标准的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/executive_standards")
public class ExecutiveStandardsController {

    @Autowired
    private IExecutiveStandardsService executiveStandardsService;

    @PreAuthorize(("hasAuthority('executive_standards:search')"))
    @ApiOperation("获取所有的执行标准信息接口")
    @GetMapping("/list")
    public Result list(){
        return Result.ok(executiveStandardsService.list());
    }

    @PreAuthorize(("hasAuthority('executive_standards:search')"))
    @ApiOperation("查询执行标准详情接口")
    @ApiImplicitParam(name = "id",value = "执行标准ID",required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable("id") String id){
        ExecutiveStandards executiveStandards = executiveStandardsService.getById(id);
        return Result.ok(executiveStandards);
    }

    @PreAuthorize(("hasAuthority('executive_standards:edit')"))
    @ApiOperation("修改执行标准信息接口")
    @PutMapping
    public Result update(@RequestBody ExecutiveStandards executiveStandards){
        executiveStandardsService.updateById(executiveStandards);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('executive_standards:add')"))
    @ApiOperation("新增执行标准信息接口")
    @PostMapping
    public Result save(@RequestBody ExecutiveStandards executiveStandards){
        executiveStandardsService.save(executiveStandards);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('executive_standards:delete')"))
    @ApiOperation("删除执行标准信息接口")
    @ApiImplicitParam(name = "id",value = "执行标准ID",required = true)
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id){
        executiveStandardsService.removeById(id);
        return Result.ok();
    }
}
